﻿//29014.3 ISYC 309 - 04a - 外径切槽和切断用可转位刀片车刀

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{
    class class_ISYC_309_04a
    {
        public static void ISYC_309_F95a(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            /*double H = 19.47;
            double LPR = 38.55;
            double HF = 19.58;
            double LS = 47.72;
            double OAL = 79.2;
            double CDX = 12.53;
            double B = 19.37;
            double WF = 19.37;
            double WTA = 9.68;
            double ECA = 26;
            double CW = 6.6;
            double ECD = 3.81;
            double KAPR = 90;
            double scale = OAL / 79.2;*/

            double H = Convert.ToDouble(data["h"]);
            double LPR = Convert.ToDouble(data["lpr"]);
            double HF = Convert.ToDouble(data["hf"]);
            double LS = Convert.ToDouble(data["ls"]);
            double OAL = Convert.ToDouble(data["oal"]);
            double CDX = Convert.ToDouble(data["cdx"]);
            double B = Convert.ToDouble(data["b"]);
            double WF = Convert.ToDouble(data["wf"]);
            double WTA = Convert.ToDouble(data["wta"]);
            double ECA = Convert.ToDouble(data["eca"]);
            double CW = Convert.ToDouble(data["cw"]);
            double ECD = Convert.ToDouble(data["ecd"]);
            double KAPR = Convert.ToDouble(data["kapr"]);
            double scale = Convert.ToDouble(data["oal"]) / 79.2;

            //点---------------------------------------------------------------------------------------------
            //第一部分
            //轮廓点
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X, v1.Y + H);
            Vector2 v3 = new Vector2(v2.X + LS, v2.Y);
            Vector2 v4 = fun.Polar(v3, 45 * pi / 180, H / 5.0);
            Vector2 v5 = new Vector2(v4.X + LPR / 3.0, v4.Y);
            Vector2 v10 = new Vector2(v1.X + OAL, v1.Y + HF);
            Vector2 v11 = fun.Polar(v10, -169 * pi / 180, CDX / Math.Cos(11 * pi / 180));
            Vector2 v12 = new Vector2(v11.X, v11.Y - HF * 0.2);
            Vector2 v13 = fun.Inters(v12, fun.Polar(v12, 6 * pi / 180, OAL), v10, fun.Polar(v10, -90 * pi / 180, OAL));
            Vector2 v6 = fun.Inters(v5, fun.Polar(v5, -20 * pi / 180, OAL), v11, v10);
            Vector2 v7 = fun.Inters(v6, fun.Polar(v6, -75 * pi / 180, OAL), v12, v13);
            Vector2 v8 = fun.Polar(v7, -96 * pi / 180, HF / 5.0);
            Vector2 v9 = fun.Inters(v1, fun.Polar(v1, 0 * pi / 180, OAL), v8, fun.Polar(v8, -106 * pi / 180, OAL));
            Vector2 v14 = new Vector2(v10.X - LPR, v2.Y);

            //第二部分
            //轮廓点
            Vector2 v15 = new Vector2(v1.X, v1.Y - H * 3);
            Vector2 v16 = new Vector2(v15.X + LS + (OAL - CDX - LS) * 0.6, v15.Y);
            Vector2 v17 = fun.Polar(v16, -ECA * pi / 180, ECD / Math.Sin(ECA * pi / 180));
            Vector2 v18 = new Vector2(v17.X, v16.Y - (WF - CW) * 1.05);
            Vector2 v19 = new Vector2(v18.X + CDX * 0.8, v18.Y);
            Vector2 v20 = new Vector2(v15.X + OAL, v15.Y - (WF - CW));
            Vector2 v21 = new Vector2(v15.X + OAL, v16.Y - WF);
            Vector2 v22 = new Vector2(v21.X, v21.Y + fun.CalDistance(v20, v21) / 2.0);
            Vector2 v23 = new Vector2(v15.X, v15.Y - B);
            Vector2 v24 = new Vector2(v15.X + LS, v15.Y);
            Vector2 v25 = new Vector2(v4.X, v24.Y);
            Vector2 v26 = fun.Inters(v25, fun.Polar(v25, -90 * pi / 180, OAL), v21, v23);
            Vector2 v27 = fun.Inters(v24, fun.Polar(v24, -90 * pi / 180, OAL), v21, v23);
            Vector2 v28 = fun.Inters(v19, fun.Polar(v19, -90 * pi / 180, OAL), v21, v23);
            Vector2 v29 = new Vector2(v15.X + OAL / 2.0, v23.Y + WTA);

            //作图部分-----------------------------------------------------------------------
            //第一部分
            //轮廓
            LwPolyline polyline1 = new LwPolyline();
            polyline1.Vertexes.Add(new LwPolylineVertex(v1));
            polyline1.Vertexes.Add(new LwPolylineVertex(v2));
            polyline1.Vertexes.Add(new LwPolylineVertex(v3));
            polyline1.Vertexes.Add(new LwPolylineVertex(v4));
            polyline1.Vertexes.Add(new LwPolylineVertex(v5));
            polyline1.Vertexes.Add(new LwPolylineVertex(v6));
            polyline1.Vertexes.Add(new LwPolylineVertex(v7));
            polyline1.Vertexes.Add(new LwPolylineVertex(v8));
            polyline1.Vertexes.Add(new LwPolylineVertex(v9));
            polyline1.Vertexes.Add(new LwPolylineVertex(v1));
            fun.PolyFill(dxf, polyline1, 0.3, contour);

            LwPolyline polyline2 = new LwPolyline();
            polyline2.Vertexes.Add(new LwPolylineVertex(v10));
            polyline2.Vertexes.Add(new LwPolylineVertex(v11));
            polyline2.Vertexes.Add(new LwPolylineVertex(v12));
            polyline2.Vertexes.Add(new LwPolylineVertex(v13));
            polyline2.Vertexes.Add(new LwPolylineVertex(v10));
            fun.PolyFill(dxf, polyline2, 0.3, contour);

            //第二部分
            //轮廓
            LwPolyline polyline3 = new LwPolyline();
            polyline3.Vertexes.Add(new LwPolylineVertex(v15));
            polyline3.Vertexes.Add(new LwPolylineVertex(v16));
            polyline3.Vertexes.Add(new LwPolylineVertex(v17));
            polyline3.Vertexes.Add(new LwPolylineVertex(v18));
            polyline3.Vertexes.Add(new LwPolylineVertex(v19));
            polyline3.Vertexes.Add(new LwPolylineVertex(v20));
            polyline3.Vertexes.Add(new LwPolylineVertex(v21));
            polyline3.Vertexes.Add(new LwPolylineVertex(v23));
            polyline3.Vertexes.Add(new LwPolylineVertex(v15));
            fun.PolyFill(dxf, polyline3, 0.3, contour);

            LwPolyline polyline4 = new LwPolyline();
            polyline4.Vertexes.Add(new LwPolylineVertex(v24));
            polyline4.Vertexes.Add(new LwPolylineVertex(v27));
            fun.PolyFill(dxf, polyline4, 0.3, contour);

            LwPolyline polyline5 = new LwPolyline();
            polyline5.Vertexes.Add(new LwPolylineVertex(v25));
            polyline5.Vertexes.Add(new LwPolylineVertex(v26));
            fun.PolyFill(dxf, polyline5, 0.3, contour);

            LwPolyline polyline6 = new LwPolyline();
            polyline6.Vertexes.Add(new LwPolylineVertex(v19));
            polyline6.Vertexes.Add(new LwPolylineVertex(v28));
            fun.PolyFill(dxf, polyline6, 0.3, contour);

            //标注---------------------------------------------------------------------------
            double height = 4 * scale;
            double arrowsize = 2 * scale;
            double exline = 0.5 * scale;

            //坐标系
            /*fun.Axis(dxf, v1, 180, 90, "Z", "Y", "", 0.3, height / 2.0, 0);
            fun.Axis(dxf, v14, 180, 90, "Z", "Y", "", 0.3, height / 2.0, 0);
            fun.Axis(dxf, v10, 180, 90, "Y", "Z", "", 0.3, height / 2.0, 0);
            fun.Axis(dxf, v15, 180, 270, "Z", "X", "", 0.3, height / 2.0, 0);
            fun.Axis(dxf, v29, 180, 270, "Z", "X", "", 0.3, height / 2.0, 0);
            fun.Axis(dxf, v22, 180, 90, "Y", "X", "", 0.3, height / 2.0, 0);*/

            //H
            fun.dimrot1(dxf, v1, v2, 90, LS * 0.2, 1, height, arrowsize, exline, "H", " ", " ");

            //LPR
            fun.dimrot1(dxf, v14, v10, 0, HF * 0.5, 1, height, arrowsize, exline, "LPR,LTA", " ", " ");

            //HF
            fun.dimrot1(dxf, v9, v10, -90, LS * 0.3, 1, height, arrowsize, exline, "HF", " ", " ");

            //HTA
            Line line1 = new Line(v10, new Vector2(v10.X + LS * 0.6, v10.Y));
            line1.Layer = dimensioning;
            dxf.AddEntity(line1);

            fun.jt1(dxf, new Vector2(v10.X + LS * 0.6, v10.Y), 90, H * 0.5, 0, "HTA", height);
            fun.jt1(dxf, new Vector2(v10.X + LS * 0.6, v10.Y), -90, H * 0.2, 0, "", height);

            //B
            fun.dimrot1(dxf, v15, v23, 90, LS * 0.3, 1, height, arrowsize, exline, "B", " ", " ");

            //LS
            fun.dimrot1(dxf, v23, v27, 180, B * 0.5, 1, height, arrowsize, exline, "LS", " ", " ");

            //OAL
            fun.dimrot1(dxf, v23, v21, 180, B, 1, height, arrowsize, exline, "OAL,LF", " ", " ");

            //CDX
            fun.dimrot1(dxf, v18, v21, 180, B * 0.5 + fun.CalDistance(v19, v28) / 2.0, 1, height, arrowsize, exline, "CDX", " ", " ");

            //ECD
            fun.dimrot1(dxf, v16, v17, -90, LS * 0.5 + (v21.X - (v16.X + Math.Abs(v17.X - v16.X) / 2.0)), 1, height, arrowsize, exline, "ECD", " ", " ");

            //WF
            fun.dimrot1(dxf, v16, v21, -90, LS + Math.Abs(v21.X - v16.X) / 2.0, 1, height, arrowsize, exline, "WF", " ", " ");

            //WTA
            fun.dimrot1(dxf, v29, v21, -90, LS * 0.7 + Math.Abs(v21.X - v29.X) / 2.0, 1, height, arrowsize, exline, "WTA", " ", " ");

            //CW
            fun.dimrot1(dxf, v21, v20, -90, LS * 0.5, 1, height, arrowsize, exline, "CW", " ", " ");

            //CCMS
            //fun.jt1(dxf, new Vector2(v15.X + fun.CalDistance(v15, v24) * 0.6, v15.Y), 150, B * 0.5, 0, "CCMS", height);

            //CSW,CRP
            /*Vector2 dian1 = fun.Polar(v10, 35 * pi / 180, H * 0.3);
            Line line2 = new Line(v10, dian1);
            line2.Layer = dimensioning;
            dxf.AddEntity(line2);

            fun.text(dxf, dian1, height, "CSW,CRP");*/

            //MCS
           /* Vector2 dian2 = fun.Polar(v14, -113 * pi / 180, 39.92 * scale);
            Vector2 dian3 = fun.Polar(v29, 109 * pi / 180, 45.22 * scale);

            Line line3 = new Line(v14, dian2);
            line3.Layer = dimensioning;
            dxf.AddEntity(line3);
            Line line4 = new Line(v29, dian3);
            line4.Layer = dimensioning;
            dxf.AddEntity(line4);

            String string1 = "MCS";
            fun.text(dxf, new Vector2(dian3.X - string1.Length / 2.0 * height, dian3.Y), height, "MCS");*/

            //PCS
            /*Vector2 dian4 = fun.Polar(v1, -117 * pi / 180, 21.43 * scale);
            Vector2 dian5 = fun.Polar(v15, 108 * pi / 180, 33.27 * scale);

            Line line5 = new Line(v1, dian4);
            line5.Layer = dimensioning;
            dxf.AddEntity(line5);
            Line line6 = new Line(v15, dian5);
            line6.Layer = dimensioning;
            dxf.AddEntity(line6);

            String string2 = "PCS";
            fun.text(dxf, new Vector2(dian5.X - string1.Length / 2.0 * height, dian5.Y), height, "PCS");*/

            //CSW
            /*Vector2 dian6 = fun.Polar(v22, 125 * pi / 180, 23 * scale);

            Line line7 = new Line(v22, dian6);
            line7.Layer = dimensioning;
            dxf.AddEntity(line7);

            fun.text(dxf, dian6, height, "CSW");
            
            //CRP
            Vector2 dian7 = fun.Polar(v22, -60 * pi / 180, 8 * scale);

            Line line8 = new Line(v21, dian7);
            line8.Layer = dimensioning;
            dxf.AddEntity(line8);

            fun.text(dxf, dian7, height, "CRP");*/

            //FDP
            Vector2 dian8 = new Vector2(v21.X + 31.03 * scale, v21.Y - 18.69 * scale);

            //fun.jt1(dxf, dian8, 180, 18, 0, "FDP", height);

            //罗马数字2
            /*fun.dimrot1(dxf, v24, v29, 90, fun.CalDistance(v15, v24) * 0.5, 1, height, arrowsize, exline, "II", " ", " ");
            fun.dimrot1(dxf, v27, v29, 90, fun.CalDistance(v15, v24) * 0.5, 1, height, arrowsize, exline, "II", " ", " ");*/

            //角度标注
            //ECA
            fun.jdbz2(dxf, new Line(v17, fun.Polar(v17, -26 * pi / 180, 0.1)), new Line(v16, fun.Polar(v16, 0 * pi / 180, 0.1)), LS * 0.55, height, arrowsize, exline, "ECA", "", "");

            //KAPR
            fun.jdbz2(dxf, new Line(v21, fun.Polar(v21, 0 * pi / 180, 0.1)), new Line(v20, fun.Polar(v20, 90 * pi / 180, 0.1)), LS * 1.2, height, arrowsize, exline, "KAPR", "", "");

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
